package com.fjut.controller;


import com.fjut.model.vod.Chapter;
import com.fjut.result.Result;
import com.fjut.service.ChapterService;
import com.fjut.vo.vod.ChapterVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author DengTianxun
 * @since 2023-03-06
 */
@Api(tags = "章节接口")
@RestController
@RequestMapping("/fjut/vod/chapter")
//@CrossOrigin
public class ChapterController {

    @Autowired
    private ChapterService chapterService;

    @ApiOperation("大纲列表")
    @GetMapping("getNestedTreeList/{courseId}")
    public Result getNestedTreeList(@PathVariable Long courseId){
        return Result.success(chapterService.getNestedTreeList(courseId));
    }

    @ApiOperation("添加课程大纲")
    @PostMapping("saveChapterInfo")
    public Result saveChapterInfo(@RequestBody Chapter chapter){
        return Result.success(chapterService.save(chapter)).message("添加课程成功");
    }

    @ApiOperation("查询课程")
    @GetMapping("getChapterInfo/{id}")
    public Result getChapterInfo(@PathVariable Long id){
        return Result.success(chapterService.getById(id));
    }

    @ApiOperation("修改课程大纲")
    @PostMapping("updateChapterInfo")
    public Result updateChapterInfo(@RequestBody Chapter chapter){
        return Result.success(chapterService.updateById(chapter)).message("修改课程成功");
    }

    @ApiOperation("删除课程")
    @DeleteMapping("deleteChapter/{id}")
    public Result deleteChapter(@PathVariable Long id){
        return Result.success(chapterService.removeById(id)).message("删除课程成功");
    }
}

